package com.bdq.content.api.controller;

import cn.hutool.core.convert.Convert;
import com.bdq.common.entity.common.CommonResult;
import com.bdq.common.feign.content.ContentFeign;
import com.bdq.common.feign.content.vo.ContentListVO;
import com.bdq.content.api.model.param.ContentDetailParam;
import com.bdq.content.api.model.param.ContentPostParam;
import com.bdq.content.api.model.vo.ContentDetailVO;
import com.bdq.content.application.model.cmd.ContentPostCmd;
import com.bdq.content.application.model.dto.ContentDetailAppDTO;
import com.bdq.content.application.model.dto.ContentListAppDTO;
import com.bdq.content.application.model.query.ContentDetailQry;
import com.bdq.content.application.service.ContentCmdService;
import com.bdq.content.application.service.ContentQueryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * bdq-content内容相关
 *
 * @author malei
 * @date 2024-05-10 11:13
 */
@RestController
@RequestMapping("/content")
public class ContentController {

    @Resource
    private ContentCmdService contentCmdService;

    @Resource
    private ContentQueryService contentQueryService;


    /**
     * 内容发布
     *
     * @return
     */
    @PostMapping("/post")
    public CommonResult<Boolean> postContent(@RequestBody @Validated ContentPostParam param) {
        contentCmdService.postContent(Convert.convert(ContentPostCmd.class, param));
        return CommonResult.success(true);
    }

    /**
     * 内容详情
     *
     * @return
     */
    @GetMapping("/detail")
    public CommonResult<ContentDetailVO> detail(@Validated ContentDetailParam param) {
        ContentDetailAppDTO contentDetailAppDTO = contentQueryService.detail(Convert.convert(ContentDetailQry.class, param));
        return CommonResult.success(Convert.convert(ContentDetailVO.class, contentDetailAppDTO));
    }
}
